<?php
	 echo $this->Html->css('jquery.multiselect');
	 echo $this->Html->script('jquery.multiselect');
	 echo $this->Html->css(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete'));
	 echo $this->Html->script(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete','autocombo')); 
?>
<script type="text/javascript">
<!--
$(function(){
	$('#phloai').hide();
/*
	$('.up').live('click',function(){
		root=$('#root').val();
		$(this).attr('src',root+'img/down.png');
		$('#phloai').hide(1000);
		$(this).attr('class','down');
		});
	$('.down').live('click',function(){
		root=$('#root').val();
		$(this).attr('src',root+'img/up.png');
		$('#phloai').show(1000);
		$(this).attr('class','up');
		});
	*/	
$("#dscol").multiselect({
	   selectedText: "Đã chọn # trong # cột",
	   checkAllText: 'Chọn tất cả',
		uncheckAllText: 'Bỏ tất cả',
	   noneSelectedText: ' -- Tất cả --'
	});
	
$( "#dantoc" ).combobox();
$( "#nganh" ).combobox();
$( "#tinhtp" ).combobox();

$('#hoten').keydown(function(e) {
    if ( e.keyCode !=13) {}
    else {e.preventDefault(); }  
    });
$('#mssv').keydown(function(e) {
    if ( e.keyCode !=13) {}
    else {e.preventDefault(); }  
    });
});
//-->
</script>
<script>
$(function() {
	$( "#tabs" ).tabs({
	    select: function(event, ui) {
	        var url = $.data(ui.tab, 'load.tabs');
	        if( url ) {
	            location.href = url;
	            return false;
	        }
	        return true;
	    },
	selected: 0 
	});
});
</script>
<div class="index" id="timkiemtt">
<?php if($isajax==0){?>
<div id="tabs">
	<ul>
        <li><a href='#timkiemtt'>Tìm kiếm thông tin</a> </li>
        <li><?php echo $this->Html->link(__('Tìm kiếm theo điểm', true), array('action' => 'searchdiemsv')); ?></li>
	</ul>
<?php echo $form->create('Z1sinhvien');?>
<?php echo $form->input('root',array('id'=>'root','type'=>'hidden','value'=>$this->webroot));?>
<h2 style="text-align:center"> Tìm kiếm thông tin đoàn viên</h2>
<table>
<tr>
	<td><?php echo $form->input('hoten',array('id'=>'hoten','label'=>'Họ tên','type'=>'text'));?></td>
	<td><?php echo $form->input('mssv',array('id'=>'mssv','label'=>'MSSV','type'=>'text'));?></td>
	<td><?php echo $form->input('phai',array('id'=>'phai','label'=>'Giới tính','type'=>'select','options'=>array('Nam'=>'Nam','Nữ'=>'Nữ'),'empty'=>'--Chọn giới tính--'));?></td>
	<td><?php echo $form->input('khoahoc',array('id'=>'khoahoc','label'=>'Khóa học','type'=>'select','options'=>$khoahocs,'empty'=>'--Chọn khóa học--'));?></td>
</tr>
<tr>
	<td><?php echo $form->input('nganh',array('id'=>'nganh','label'=>'Ngành','type'=>'select','options'=>$nganhs,'empty'=>''));?></td>
	<td><?php echo $form->input('tendantoc',array('id'=>'dantoc','label'=>'Dân tộc','type'=>'select','options'=>$dantocs,'empty'=>'--Chọn dân tộc--'));?></td>
	<td><?php echo $form->input('tentinhtp',array('id'=>'tinhtp','label'=>'Quê quán','type'=>'select','options'=>$quequans,'empty'=>'--Chọn tỉnh--'));?></td>
	<td><?php echo $form->input('doituong',array('id'=>'doituong','label'=>'Đối tượng','type'=>'select','options'=>array(0=>'Đoàn viên',1=>'Đảng viên'),'empty'=>'--Chọn đối tượng--'));?></td>
</tr>
<tr>
</tr>
<tr>
<td><?php echo $form->input('xeploai',array('id'=>'xeploai','label'=>'Chọn loại','type'=>'select','options'=>$xeploais,'empty'=>' -- Chọn Xếp loại --'));?></td>
<td><?php echo $form->input('namhoc',array('id'=>'namhoc','label'=>'Chọn năm học','type'=>'select','options'=>$namhocs,'empty'=>' -- Chọn Năm học --'));?></td>
<td>
	<div id='hocky'>
		<?php echo $form->input('hocky',array('id'=>'hocky','label'=>'Chọn học kỳ','type'=>'select','options'=>(empty($hockys)?array():$hockys),'empty'=>' -- Chọn Học kỳ --'));?>
	</div>
</td>
</tr>
<tr>
<td><?php echo $form->input('dscol',array('id'=>'dscol','label'=>'Cột hiển thị','multiple'=>'multiple','options'=>$dscol,'empty'=>'','style'=>'width: 100px;'));?></td>
<td>
		<?php echo $form->input('sapxep',array('id'=>'sapxep','label'=>'Sắp xếp theo','type'=>'select','options'=>array('mssv'=>'Mã số SV','phai'=>'Phái','tennganh'=>'Ngành','tenchidoan'=>'Chi đoàn')));?>
		<?php echo $form->input('loaixs',array('id'=>'loaixs','label'=>'Thứ tự','type'=>'select','options'=>array('ASC'=>'Tăng dần','DESC'=>'Giảm dần')));?>
	</td>
	<td><?php echo $js->submit('  Tìm  ',array('url'=>array('controller'=>'z1sinhviens','action'=>'searchsv'),'update'=>'#kqtimkiem'));?></td>
</tr>
</table>

<div id='kqtimkiem'>
<?php if(!empty($sinhviens)){?>
	<div>
<div id='left' style="float:left"><?php echo $html->link('Xuất Ecxel kết quả',array('controller'=>'z1sinhviens','action'=>'xuatexcel',$name))?></div>
	<div class="paging" id='right' style="float:right">
	<?php $this->Paginator->options(array('url' => array($name)));?>
	<?php echo $this->Paginator->counter(array('format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)));?>
		<?php echo $this->Paginator->prev('<< ' . __('Sau', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Trước', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
</div>
	<table id='tables'>
	<tr>
	<?php foreach ($cothienthi as $tencot):?>
			<th><?php echo $tencot?></th>
	<?php endforeach;?>
	</tr>
	<?php
	$i = 0;
	foreach ($sinhviens as $sinhvien):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<?php foreach ($cothienthi as $keycot => $tencot):?>
		<td>
			<?php
				if($keycot=='tendantoc')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['dantoc'][$keycot];
				elseif($keycot=='tentinhtp')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['tinhtp'][$keycot];
				elseif($keycot=='tennganh')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['nganh'][$keycot];  
				else
					echo $sinhvien['Z1sinhvien'][$keycot];
			?>
		</td>
		<?php endforeach;?>
	</tr>
<?php endforeach; ?>
	</table>
	<div class="paging">
	<?php echo $this->Paginator->counter(array('format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)));?>
		<?php echo $this->Paginator->prev('<< ' . __('Sau', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Trước', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
	<?php }?>
</div>
</div>
<?php }else{?>
<?php if(!empty($sinhviens)){?>
<div>
<div id='left' style="float:left"><?php echo $html->link('Xuất Ecxel kết quả',array('controller'=>'z1sinhviens','action'=>'xuatexcel',$name))?></div>
	<div class="paging" id='right' style="float:right">
	<?php $this->Paginator->options(array('url' => array($name)));?>
	<?php echo $this->Paginator->counter(array('format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)));?>
		<?php echo $this->Paginator->prev('<< ' . __('Sau', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Trước', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
</div>
	<table id='tables'>
	<tr>
	<?php foreach ($cothienthi as $tencot):?>
			<th><?php echo $tencot?></th>
	<?php endforeach;?>
	</tr>
	<?php
	$i = 0;
	foreach ($sinhviens as $sinhvien):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<?php foreach ($cothienthi as $keycot => $tencot):?>
		<td>
			<?php
				if($keycot=='tendantoc')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['dantoc'][$keycot];
				elseif($keycot=='tentinhtp')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['tinhtp'][$keycot];
				elseif($keycot=='tennganh')
					if(isset($sinhvien['Z1sinhvien'][$keycot])) 
						echo $sinhvien['Z1sinhvien'][$keycot];
					else
						echo $sinhvien['nganh'][$keycot];  
				else
					echo $sinhvien['Z1sinhvien'][$keycot];
			?>
		</td>
		<?php endforeach;?>
	</tr>
<?php endforeach; ?>
	</table>
<div class="paging">
<?php echo $this->Paginator->counter(array('format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)));?>
		<?php echo $this->Paginator->prev('<< ' . __('Sau', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Trước', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
<?php }else{?>
<h2>Không có dữ liệu</h2>
<?php }}?>
<?php $this->Js->get('#namhoc')->event('change',
							$this->Js->request(array('controller' => 'z1sinhviens', 'action' => 'layhocky'),
							array('update' => '#hocky','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>
</div>